home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Utilities / MView / gxu / d3dx9dbg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  3.8 KB  |  170 lines

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (C) 1999 Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //  File:       d3dx9dbg.cpp
  6. //  Content:    D3DX debugging functions
  7. //
  8. ///////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "pchgxu.h"
  11.  
  12.  
  13. #if DBG
  14.  
  15. static BOOL g_bDebugMute = FALSE;
  16.  
  17.  
  18. //
  19. // DPF
  20. //
  21.  
  22. void cdecl D3DXDebugPrintfMView(UINT lvl, LPSTR szFormat, ...)
  23. {
  24.     static UINT uDebugLevel = (UINT) -1;
  25.  
  26.     char strA[256];
  27.     char strB[256];
  28.  
  29.     if((UINT) -1 == uDebugLevel)
  30.         uDebugLevel = GetProfileInt("Direct3D", "debug", 0);
  31.  
  32.     if((lvl > uDebugLevel) || g_bDebugMute)
  33.         return;
  34.  
  35.     va_list ap;
  36.     va_start(ap, szFormat);
  37.     _vsnprintf(strA, sizeof(strA), szFormat, ap);
  38.     strA[255] = '\0';
  39.     va_end(ap);
  40.  
  41.     _snprintf(strB, sizeof(strB), "D3DX: %s\r\n", strA);
  42.     strB[255] = '\0';
  43.  
  44.     OutputDebugStringA(strB);
  45. }
  46.  
  47.  
  48. //
  49. // D3DXASSERT
  50. //
  51.  
  52. int WINAPI D3DXDebugAssertMView(LPCSTR szFile, int nLine, LPCSTR szCondition)
  53. {
  54.     typedef BOOL (*PFNBV)(VOID);
  55.  
  56.     static DWORD dwValue = 0;
  57.     static BOOL bInit = FALSE;
  58.     static PFNBV pIsDebuggerPresent = NULL;
  59.  
  60.     LONG err;
  61.     char str[256];
  62.  
  63.  
  64.     // Print message to debug console
  65.     DPF(0, "Assertion failure! (%s %d): %s", szFile, nLine, szCondition);
  66.  
  67.  
  68.     // Initialize stuff
  69.     if(!bInit)
  70.     {
  71.         HKEY hkey;
  72.         DWORD dwType;
  73.         DWORD cbValue = sizeof(DWORD);
  74.         HINSTANCE hinst;
  75.  
  76.         bInit = TRUE;
  77.  
  78.         // Get IsDebuggerPresent entry point
  79.         if((hinst = (HINSTANCE) GetModuleHandle("kernel32.dll")) ||
  80.            (hinst = (HINSTANCE) LoadLibrary("kernel32.dll")))
  81.         {
  82.             pIsDebuggerPresent = (PFNBV) GetProcAddress(hinst, "IsDebuggerPresent");
  83.         }
  84.  
  85.         // Get debug level from registry
  86.         err = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Direct3D", &hkey);
  87.  
  88.         if(ERROR_SUCCESS != err)
  89.             return 0;
  90.  
  91.         err = RegQueryValueEx(hkey, "D3DX", NULL, &dwType, (LPBYTE) &dwValue, &cbValue);
  92.  
  93.         RegCloseKey(hkey);
  94.  
  95.         if(ERROR_SUCCESS != err || REG_DWORD != dwType || cbValue != sizeof(DWORD))
  96.             return 0;
  97.     }
  98.  
  99.     if(0 == dwValue)
  100.         return 0;
  101.  
  102.     if(1 == dwValue)
  103.         return 1;
  104.  
  105.  
  106.     // Display a message box if no debugger is present
  107.     if((dwValue == 3) || (pIsDebuggerPresent && !pIsDebuggerPresent()))
  108.     {
  109.         _snprintf(str, sizeof(str), "File:\t %s\nLine:\t %d\nAssertion:\t%s\n\nDo you want to invoke the debugger?", szFile, nLine, szCondition);
  110.         err = MessageBox(NULL, str, "D3DX Assertion Failure", MB_SYSTEMMODAL | MB_YESNOCANCEL);
  111.  
  112.         switch(err)
  113.         {
  114.         case IDYES:     return 1;
  115.         case IDNO:      return 0;
  116.         case IDCANCEL:  FatalAppExit(0, "D3DX Assertion Failure.. Application terminated"); return 1;
  117.         }
  118.     }
  119.  
  120.     return 0;
  121. }
  122.  
  123.  
  124. #endif // DBG
  125.  
  126. #if 0
  127. //
  128. // DPF_MUTE
  129. //
  130.  
  131. typedef void (*LPDEBUGSETMUTE)(BOOL);
  132.  
  133. void D3DXDebugMute(BOOL bMute)
  134. {
  135.     static LPDEBUGSETMUTE pDSM_D3D9  = NULL;
  136.     static LPDEBUGSETMUTE pDSM_D3D9D = NULL;
  137.  
  138.  
  139.     // Mute D3DX
  140. #if DBG
  141.     g_bDebugMute = bMute;
  142. #endif
  143.  
  144.  
  145.     // Mute D3D9
  146.     if(!pDSM_D3D9 && !pDSM_D3D9D)
  147.     {
  148.         HINSTANCE hInst;
  149.  
  150.         if(GetModuleHandle("d3d9.dll"))
  151.         {
  152.             if((hInst = (HINSTANCE) LoadLibrary("d3d9.dll")))
  153.                 pDSM_D3D9 = (LPDEBUGSETMUTE) GetProcAddress(hInst, "DebugSetMute");
  154.         }
  155.  
  156.         if(GetModuleHandle("d3d9d.dll"))
  157.         {
  158.             if((hInst = (HINSTANCE) LoadLibrary("d3d9d.dll")))
  159.                 pDSM_D3D9D = (LPDEBUGSETMUTE) GetProcAddress(hInst, "DebugSetMute");
  160.         }
  161.     }
  162.  
  163.  
  164.     if(pDSM_D3D9)
  165.         pDSM_D3D9(bMute);
  166.  
  167.     if(pDSM_D3D9D)
  168.         pDSM_D3D9D(bMute);
  169. }
  170. #endif